package com.frkj.yuan.activity;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.frkj.yuan.R;
import com.frkj.yuan.adapter.YouhuiQuanListAdapter;
import com.frkj.yuan.base.BaseActivity;
import com.frkj.yuan.fragment.my.CouponsJiJiangGuoQiFragment;
import com.frkj.yuan.fragment.my.CouponsLapseFragment;
import com.frkj.yuan.fragment.my.CouponsNotUsedFragment;
import com.frkj.yuan.fragment.my.UsedCouponsFragment;
import com.frkj.yuan.utils.FullScreenUtils;

import java.util.ArrayList;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * 信息说明: 优惠券界面
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/3/1 18 ：04
 * 项目名称：yuanban
 */
public class YouhuiQuanListActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener  {
    @BindView(R.id.base_title)
    TextView mTitleMesg;
    @BindView(R.id.rag_group)
    RadioGroup mRadgroup;
    @BindView(R.id.view_pager)
    ViewPager mViewPager;
    private ArrayList<Fragment> mList = new ArrayList<>();
    @Override
    public int getLayoutId() {
        return R.layout.activity_youhuiquan_view;
    }
    @OnClick(R.id.base_back)
    public void OnClick(){
        finishWitchAnimation();
    }
    @Override
    public void initLayoutView() {
        mTitleMesg.setText("优惠券");
        FullScreenUtils.getInstance().fullScreen(YouhuiQuanListActivity.this,true);
        initfragment();
        initView();
    }
    private void initView() {
        mViewPager.setCurrentItem(0);
        mRadgroup.check(R.id.rad_nsy);
        mRadgroup.setOnCheckedChangeListener(this);
        mViewPager.setOnPageChangeListener(this);
        mViewPager.setAdapter(new YouhuiQuanListAdapter(getSupportFragmentManager(), mList));
    }
    private void initfragment() {
        CouponsNotUsedFragment notUsedFragment = new CouponsNotUsedFragment();
        mList.add(notUsedFragment);
        CouponsJiJiangGuoQiFragment jiJiangGuoQiFragment = new CouponsJiJiangGuoQiFragment();
        mList.add(jiJiangGuoQiFragment);
        UsedCouponsFragment usedCouponsFragment = new UsedCouponsFragment();
        mList.add(usedCouponsFragment);
        CouponsLapseFragment lapseFragment = new CouponsLapseFragment();
        mList.add(lapseFragment);
    }
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rad_nsy:
                mViewPager.setCurrentItem(0, false);
                break;
            case R.id.rad_yishiyong:
                mViewPager.setCurrentItem(1, false);
                break;
            case R.id.rad_guoqi:
                mViewPager.setCurrentItem(2, false);
                break;
            case R.id.rad_shixiao:
                mViewPager.setCurrentItem(3, false);
                break;
            default:
                break;
        }
    }
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }
    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                mRadgroup.check(R.id.rad_nsy);
                break;
            case 1:
                mRadgroup.check(R.id.rad_yishiyong);
                break;
            case 2:
                mRadgroup.check(R.id.rad_guoqi);
                break;
            case 3:
                mRadgroup.check(R.id.rad_shixiao);
                break;
            default:
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
